package com.ellricky.tc_manager

import android.app.Activity
import android.view.View
import android.widget.ImageView
import android.widget.LinearLayout
import android.widget.TextView
import androidx.cardview.widget.CardView
import androidx.core.content.ContextCompat
import com.andr.common.ui.adapter.BaseRecyclerAdapter
import com.andr.common.ui.adapter.SmartViewHolder
import com.andr.common.util.EmptyUtil
import com.andr.common.util.ResUtil
import com.andr.common.util.StrUtil
import com.ellricky.baselib.entity.task.DayTaskItemEntity
import com.ellricky.baselib.entity.task.TaskAuditEntity
import com.ellricky.baselib.entity.task.TaskSystemEntity
import com.ellricky.baselib.entity.task.TrainTaskEntity
import com.ellricky.baselib.util.GlideUtil
import de.hdodenhof.circleimageview.CircleImageView

///////////////////////////////////////////////////////////////////////////
// 首页
///////////////////////////////////////////////////////////////////////////

internal class CourseAdapter(ctx: Activity) :
        BaseRecyclerAdapter<CourseEntity>(R.layout.tm_adapter_course) {

    private val colorBlack = ContextCompat.getColor(ctx, R.color.base_list_black)
    private val colorWhite = ContextCompat.getColor(ctx, R.color.common_main_white)

    override fun onBindViewHolder(vh: SmartViewHolder?, p1: CourseEntity?, position: Int) {

        vh?.itemView?.let {

            val rootView = it.findViewById<CardView>(R.id.cvRoot)
            val tvTitle = it.findViewById<TextView>(R.id.tvTitle)
            val tvValue = it.findViewById<TextView>(R.id.tvValue)
            val tvDate = it.findViewById<TextView>(R.id.tvDate)

            val ivEnd = it.findViewById<ImageView>(R.id.ivEnd)

            val tvEndContainer = it.findViewById<LinearLayout>(R.id.tvEndContainer)
            val tvTotalNum = it.findViewById<TextView>(R.id.tvTotalNum)
            val tvAttendNum = it.findViewById<TextView>(R.id.tvAttendNum)


            tvTitle.text = p1?.classTime
            tvValue.text = p1?.classTypeName
            tvDate.text = p1?.classRoomName

            // 1-未开课  2-已开课
            val open = "2" == p1?.isOpenClass
            if (open) {
                // 已开课
                rootView?.setCardBackgroundColor(colorBlack)
                tvTitle.setTextColor(colorWhite)
                tvValue.setTextColor(colorWhite)
                tvDate.setTextColor(colorWhite)

                tvEndContainer.visibility = View.VISIBLE
                tvTotalNum.setTextColor(colorWhite)
                tvAttendNum.setTextColor(colorWhite)
                tvTotalNum.text = "应到".plus(StrUtil.filterEmpty(p1?.studentNum)).plus("人")
                tvAttendNum.text = "实到".plus(StrUtil.filterEmpty(p1?.attendNum)).plus("人")

                ivEnd.visibility = View.GONE

            } else {
                // 未开课
                rootView?.setCardBackgroundColor(colorWhite)
                tvTitle.setTextColor(colorBlack)
                tvValue.setTextColor(colorBlack)
                tvDate.setTextColor(colorBlack)

                tvEndContainer.visibility = View.GONE
                ivEnd.visibility = View.VISIBLE

            }
        }
    }


}


class WorkLogAdapter :
        BaseRecyclerAdapter<WorkLogListEntity>(R.layout.tm_adapter_work_log) {
    override fun onBindViewHolder(vh: SmartViewHolder?, p1: WorkLogListEntity?, position: Int) {
        vh?.let {
            it.text(R.id.tvTitle, p1?.name)
            it.text(R.id.tvNum, p1?.count)
            it.text(R.id.tvUnit, p1?.unit)
        }
    }
}

class TodaySignAdapter(private val ctx: Activity) : BaseRecyclerAdapter<TodaySignEntity>(com.ellricky.baselib.R.layout.base_adapter_stu_msg) {

    override fun onBindViewHolder(holder: SmartViewHolder, model: TodaySignEntity?, position: Int) {

        val cv = holder.itemView.findViewById<CircleImageView>(R.id.ivAvatar)
        GlideUtil.into(ctx, model?.headPic, cv)

        holder.text(R.id.tvName, model?.name)

        holder.text(R.id.tvDate, model?.orderDate)

        holder.text(R.id.tvClassHour, StrUtil.filterEmpty(model?.classNum).plus("课时"))

    }
}

internal class AmMeetAdapter(private val context: Activity) :
        BaseRecyclerAdapter<AmMeetEntity>(R.layout.base_adapter_common_list) {

    override fun onBindViewHolder(vh: SmartViewHolder?, p1: AmMeetEntity?, position: Int) {

        vh?.text(R.id.tvTitle, p1?.meetTitle)

        vh?.text(R.id.tvKey, context.getString(R.string.base_fz_teacher))
        vh?.text(R.id.tvValue, p1?.name)

        vh?.text(R.id.tvDateKey, context.getString(R.string.tm_am_date))
        vh?.text(R.id.tvDate, p1?.meetDate)
    }

}



















